package com.codeczx.customviewdemo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by win10 on 2017/6/26.
 */

public class BorderTextView extends android.support.v7.widget.AppCompatTextView {

    private final Paint paint;

    public BorderTextView(Context context) {
        this(context,null);
    }

    public BorderTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public BorderTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        paint.setColor(Color.BLUE);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(0,0,getMeasuredWidth(),getMeasuredHeight(),paint);
        paint.setColor(Color.YELLOW);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(10,10,getMeasuredWidth()-10,getMeasuredHeight()-10,paint);
        canvas.save();
        canvas.translate(10,0);
        super.onDraw(canvas);
        canvas.restore();
    }
}
